package controller;

import core.BaseServlet;
import dao.DepartmentDao;
import dao.impl.DepartmentDaoImpl;
import pojo.Department;
import service.BaseInfoService;
import service.WorkerService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet(name = "BaseInfoServlet", urlPatterns = "/baseInfo")
public class BaseInfoServlet extends BaseServlet {

     private BaseInfoService baseInfoService= new BaseInfoService();
     private WorkerService workerService = new WorkerService();
     private DepartmentDao departmentDao = new DepartmentDaoImpl();

    /**
     * 员工管理界面
     * @param request
     * @param response
     * @throws ServletException
     * @throws IOException
     */
    public void workerManagePage(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // 获取所有部门信息 用于按条件查找
        List<Department> departmentList = departmentDao.findAllDepartment();
        request.setAttribute("departmentList", departmentList);
        request.getRequestDispatcher("/WEB-INF/pages/baseInfo/workerManage/workerManage.jsp").forward(request, response);
    }

    /**
     * 员工管理回收站界面
     * @param request
     * @param response
     * @throws ServletException
     * @throws IOException
     */
    public void workerManageDeletedPage(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // 获取所有部门信息 用于按条件查找
        List<Department> departmentList = departmentDao.findAllDepartment();
        request.setAttribute("departmentList", departmentList);
        request.getRequestDispatcher("/WEB-INF/pages/baseInfo/workerManage/workerManageDeleted.jsp").forward(request, response);
    }

    /**
     * 员工管理界面
     * @param request
     * @param response
     * @throws ServletException
     * @throws IOException
     */
    public void workerManage(HttpServletRequest request, HttpServletResponse response) {

        //baseInfoService.workerList(request, response);
        baseInfoService.findWorkerByParam(request, response);
    }

    /**
     * 删除员工(软删除)
     * @param request
     * @param response
     * @throws ServletException
     * @throws IOException
     */
    public void delete(HttpServletRequest request, HttpServletResponse response) {
        baseInfoService.delete(request, response);
    }

    /**
     * 删除员工（真删）
     * @param request
     * @param response
     * @throws ServletException
     * @throws IOException
     */
    public void realDelete(HttpServletRequest request, HttpServletResponse response) {
        baseInfoService.realDelete(request, response);
    }

    /**
     * 恢复员工
     * @param request
     * @param response
     * @throws ServletException
     * @throws IOException
     */
    public void restore(HttpServletRequest request, HttpServletResponse response) {
        baseInfoService.restore(request, response);
    }

    /**
     * 编辑员工界面
     * @param request
     * @param response
     * @throws ServletException
     * @throws IOException
     */
    public void editWorkerPage(HttpServletRequest request, HttpServletResponse response) {
        baseInfoService.showEditWorker(request, response);
    }

    /**
     * 添加员工页面
     * @param request
     * @param response
     * @throws ServletException
     * @throws IOException
     */
    public void addPage(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.getRequestDispatcher("/WEB-INF/pages/baseInfo/workerManage/workerAdd.jsp").forward(request, response);
    }

    /**
     * 添加员工
     * @param request
     * @param response
     * @throws ServletException
     * @throws IOException
     */
    public void add(HttpServletRequest request, HttpServletResponse response) {
        workerService.add(request, response);
    }

    /**
     * 编辑员工
     * @param request
     * @param response
     * @throws ServletException
     * @throws IOException
     */
    public void edit(HttpServletRequest request, HttpServletResponse response) {
        baseInfoService.edit(request, response);
    }

    /**
     * 根据条件查找员工
     * @param request
     * @param response
     */
    public void findWorkByParam(HttpServletRequest request, HttpServletResponse response){
        baseInfoService.findWorkerByParam(request, response);
    }
}
